//
//  indexViewController.m
//  NBAPro
//
//  Created by 李广松 on 16/6/26.
//  Copyright © 2016年 WYH. All rights reserved.
//

#import "IndexViewController.h"

@interface IndexViewController () {
    
    UILabel *btnLineLab;

}

@end

@implementation IndexViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tabBar.frame = CGRectMake(0, 0, 0, 0);
    
    UIView *indexTabView = [[UIView alloc] initWithFrame:CGRectMake(0, 110, self.view.frame.size.width, 40)];
    indexTabView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
    [self.view addSubview:indexTabView];
    

    [self createIndexButton];
    
    [self createAllController];
    
    
    
    btnLineLab = [CreateControl createLabelWithFrame:CGRectMake(25 - 3, indexTabView.frame.origin.y + indexTabView.frame.size.height - 3, [self getSizeWithString:@"Games" AndFont:15].width, 3) AndText:nil AndTextColor:nil AndBackgroundColor:[UIColor whiteColor] AndTextFont:0];
    [self.view addSubview:btnLineLab];
    
}

- (void)createAllController {
    GameViewController *gamesViewController = [[GameViewController alloc] init];
    
    PlayersViewController *playersViewController = [[PlayersViewController alloc] init];
    
    
    TeamViewController *teamViewController = [[TeamViewController alloc] init];
    
    UIViewController *rosterViewController = [[UIViewController alloc] init];    //
    rosterViewController.view.backgroundColor = [UIColor grayColor];             //
    
    self.viewControllers = [[NSArray alloc] initWithObjects:gamesViewController, playersViewController, teamViewController, rosterViewController, nil];
    self.selectedIndex = 0;

}

- (void)createIndexButton {
    UIButton *gamesBtn = [self createBtnWithFrame:CGRectMake(25, 110, [self getSizeWithString:@"Games" AndFont:15].width, 40) AndTitle:@"Games" AndTag:0 AndTarget:@selector(selectTag:)];
    [self.view addSubview:gamesBtn];

    UIButton *playersBtn = [self createBtnWithFrame:CGRectMake(gamesBtn.frame.origin.x + gamesBtn.frame.size.width + 57, 110, [self getSizeWithString:@"Players" AndFont:15].width, 40) AndTitle:@"Players" AndTag:1 AndTarget:@selector(selectTag:)];
    [self.view addSubview:playersBtn];
    
    UIButton *teamsBtn = [self createBtnWithFrame:CGRectMake(playersBtn.frame.origin.x + gamesBtn.frame.size.width + 57, 110, [self getSizeWithString:@"Teams" AndFont:15].width, 40) AndTitle:@"Teams" AndTag:2 AndTarget:@selector(selectTag:)];
    [self.view addSubview:teamsBtn];
    
    UIButton *rosterBtn = [self createBtnWithFrame:CGRectMake(teamsBtn.frame.origin.x + teamsBtn.frame.size.width + 57, 110, [self getSizeWithString:@"Roster" AndFont:15].width, 40) AndTitle:@"Roster" AndTag:3 AndTarget:@selector(selectTag:)];
    [self.view addSubview:rosterBtn];
    
}


- (UIButton *)createBtnWithFrame:(CGRect)frame AndTitle:(NSString *)title AndTag:(int)tagInt AndTarget:(SEL)select {
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setBackgroundColor:[UIColor clearColor]];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    button.tag = tagInt;
    [button addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    
    return button;
    
}

- (void)selectTag:(id)sender {
    
    UIButton *button = (UIButton *)sender;
    self.selectedIndex = button.tag;
    
    btnLineLab.frame = CGRectMake(button.frame.origin.x - 3, btnLineLab.frame.origin.y, button.frame.size.width + 7, 3);
    
}



- (CGSize)getSizeWithString:(NSString *)string AndFont:(float)font{
    CGSize size = [string sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]}];
    return size;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
